<?php

/**
 * @author binhit
 * @copyright 2009
 */

class department_model extends CI_Model
{
	function __construct()
	{
		parent::__construct('department');
	}
    
	function loadDepartment($id) {		
		$arr =  $this->model->table("department")->where('id', $id)->find_all();
		return 	$arr[0];
	}  
   
	function loadDepartmentSoap($id)
    {
		$obj = new stdClass();
        $sql_dv="SELECT ma, ten FROM (`trungtam`) where id=".$id;       
        $arr = $this->pub->ketnoi_sql($sql_dv,'get');
        //print_r($arr); exit();
		if(isset($arr[0])) {
			$obj->usercode = $arr[0]['ma'];
			$obj->names = $arr[0]['ten'];
			return $obj;
		}
    }	
	
	function loadChuyenquan($id)
    {
        $sql_dv = "SELECT `id`, `tennhanvien` as ten, taikhoan FROM (`nhanvien`) where id=".$id;      
        $arr = $this->pub->ketnoi_sql($sql_dv,'get');
		$obj = new stdClass();
		if(isset($arr[0])) {
			$obj->ma = $arr[0]['taikhoan'];
			$obj->ten = $arr[0]['ten'];
			return $obj;
		}
		return $sql_dv;
    }
    
    function loadChuyenquans($str_id)
    {
        $sql_dv = "SELECT `id`, `tennhanvien` as ten, taikhoan FROM (`nhanvien`) where id in (".$str_id.")";    
        //echo "<pre>"; print_r($sql_dv); exit();  
        $arr = $this->pub->ketnoi_sql($sql_dv,'get');
		$rarr = array();
        $rarr['ma']=",";
        $rarr['ten']=",";
		foreach($arr as $item){
			$rarr['ma'] .= $item['taikhoan'].",";
			$rarr['ten'] .= $item['ten'].",";		
		}
		return $rarr;
    }	
}
?>